package cn.tedu.ssm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.tedu.ssm.pojo.Item;
import cn.tedu.ssm.service.ItemService;

//@Controller实现标识，springmvc会进行配置，Rest会自动把返回java对象转换json字符串
@RestController	
@CrossOrigin(origins = "*")		//声明支持跨域访问，这样8848才能访问8070
public class ItemController {
	@Autowired	//自动装配，把service和controller联系起来
	private ItemService itemService;
	
	//和浏览器url对应：http://localhost:8070/item/list?num=3
	//RESTFul ：http://localhost:8070/item/list?num=3
	@RequestMapping("/item/list/{num}")
	public List<Item> list(@PathVariable Integer num){	//springmvc自动解析get请求把参数值封装到num参数中
		return itemService.list(num);
	}
}
